import urllib.request

url = 'http://www.baidu.com'
response = urllib.request.urlopen(url)
print(type(response))    # HTTPResponse


# content = response.read(5)
# print(content)
# 返回指定数量的字节
# content = response.read(5)
# print(content)

# 读取一行
# content = response.readline()
# print(content)

# 全部读取
# content = response.readlines()
# print(content)

# 获取状态码
print(response.getcode())
# 获取url
print(response.geturl())
# 获取状态信息
print(response.getheaders())